package com.campusnews.utils;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.util.HashMap;
import java.util.Map;

public class EntryToMapUtils {
    public static Map<String,Object> entryToMap(Object object) throws JsonProcessingException {
        Map<String, Object> map = new HashMap<>();
        //实体类转化为map集合
        map = JSON.parseObject(JsonUtils.toUnderlineJSONString(object), Map.class);
        //保持与数据库中的字段名相同
        map.remove("thing");
        map.remove("page");
        map.remove("page_size");
        map.remove("sort_order");
        //清楚map对象中为空的key
        map.entrySet().removeIf(entry -> entry.getValue() == null);
        map.entrySet().removeIf(entry -> entry.getValue().toString().equals(""));
        map.entrySet().removeIf(entry -> entry.getValue().toString().equals("-1"));
        System.out.println(map);
        return map;
    }
}
